//
//  XLViewController.m
//  SKP_Silk_SDK
//
//  Created by ilongge on 06/09/2024.
//  Copyright (c) 2024 ilongge. All rights reserved.
//

#import "XLViewController.h"
#import "XLSilkCodecTool.h"

@interface XLViewController ()

@end

@implementation XLViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSLog(@"%@", NSHomeDirectory());
}


- (IBAction)decodeAction:(id)sender {
    NSString *silkPath = [[NSBundle mainBundle] pathForResource:@"Voice_36" ofType:@"silk"];
    NSString *pcmPath = [NSString stringWithFormat:@"%@/Documents/decode_%@.wav", NSHomeDirectory(), [self dateFormatter]];
    [XLSilkCodecTool decodeSilkFromSilkPath:silkPath
                                toWavePath:pcmPath
                               sampleRate:8000];
}

- (IBAction)encodeAction:(id)sender {
    NSString *pcmPath = [[NSBundle mainBundle] pathForResource:@"Voice_36" ofType:@"wav"];
    NSString *silkPath = [NSString stringWithFormat:@"%@/Documents/encode_%@.silk", NSHomeDirectory(), [self dateFormatter]];
    [XLSilkCodecTool encodePcmToSilkFromWavePath:pcmPath
                                   toSilkPath:silkPath];
}

- (NSString *)dateFormatter{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy-MM-dd-HH-mm-ss-SSS";
    dateFormatter.timeZone = [NSTimeZone timeZoneWithName:@"GMT +0800"];
    return [dateFormatter stringFromDate:[NSDate date]];
}

@end
